package com.deer.wms.review.manage.web;

import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.deer.wms.review.manage.model.CaseMaster;
import com.deer.wms.review.manage.model.CaseMasterCriteria;
import com.deer.wms.review.manage.service.CaseMasterService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.deer.wms.review.manage.model.CaseMasterDto;
import springfox.documentation.annotations.ApiIgnore;


/**
* Created by guo on 2018/10/24.
*/
@Api(description = "审核内容信息api接口")
@RestController
@RequestMapping("/case/masters")
public class CaseMasterController {

    @Autowired
    private CaseMasterService caseMasterService;

    @PostMapping("/add")
    public Result add(@RequestBody CaseMaster caseMaster) {
        caseMasterService.save(caseMaster);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete( Integer caseMasterId) {
        caseMasterService.removeById(caseMasterId);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody CaseMaster caseMaster) {
        caseMasterService.updateById(caseMaster);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        CaseMaster caseMaster = caseMasterService.getById(id);
        return ResultGenerator.genSuccessResult(caseMaster);
    }

    @GetMapping("/list")
    public Result list(CaseMasterCriteria criteria, @ApiIgnore @User CurrentUser currentUser) {

        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<CaseMasterDto> list = caseMasterService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
